﻿using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace MediaPortal.Plugins.Trailers.Providers
{
    public class MovieMazeArchivPage
    {
        private const string urlArchiv = MovieMazeTrailers.urlBase + "/media/trailer/archiv.phtml";

        private const string trailerListRegExp = "(?<trailerurl>\\/media\\/trailer.*?.html)\">(?<trailername>.*?)<\\/a>";

        public Index fetchTrailerList()
        {
            Index items = new Index();
            string html = string.Empty;

            MovieMazeTrailerWebClient client = new MovieMazeTrailerWebClient();
            client.GetWebPage(urlArchiv, MovieMazeTrailers.urlBase, out html);

            MatchCollection mc = Regex.Matches(html, @trailerListRegExp);

            foreach (Match m in mc)
            {
                IndexItem item = new IndexItem();
                item.Label = m.Groups["trailername"].Value;
                item.Key = m.Groups["trailerurl"].Value;
                items.Add(item);
            }

            return items;
        }
    }
}